minetest.register_node('furniture:lectern', {
   description = 'Lectern',
   drawtype = 'mesh',
   mesh = 'furniture_lectern.obj',
   tiles = {'furniture_lectern.png',},
   overlay_tiles = {{name='furniture_lectern_overlay.png', color='white'}},
   paramtype2 = 'colorfacedir',
   palette = 'furniture_stain_palette.png',
   paramtype = 'light',
   selection_box = {
      type = 'fixed',
      fixed = {-.3, -.5, -.3, .3, .5, .3},
      },
   collision_box = {
      type = 'fixed',
      fixed = {-.3, -.5, -.3, .3, .5, .3},
      },
   groups = {breakable=1},
   after_place_node = function(pos, placer)
      local meta = minetest.get_meta(pos)
      meta:set_string('owner', placer:get_player_name())
      meta:set_string('infotext', '')
      meta:set_string('title', '')
      meta:set_string('content', '')
   end,
   on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
      local name = clicker:get_player_name()
      local meta = minetest.get_meta(pos)
      local owner = meta:get_string('owner')
      local title = meta:get_string('title')
      local content = meta:get_string('content')
      if owner == name then
         meta:set_string('formspec', furniture.lectern_edit_sign(title, content))
      else
         meta:set_string('formspec', furniture.lectern_view_sign(title, content))
      end
   end,
   on_receive_fields = function(pos, formname, fields, sender)
      local meta = minetest.get_meta(pos)
      if fields ['save'] then
         local player_name = sender:get_player_name()
         meta:set_string('infotext', fields.title)
         meta:set_string('title', fields.title)
         meta:set_string('content', fields.content)
         minetest.log("action", (player_name or "").." wrote \""..fields.title.."\" to lectern at "..minetest.pos_to_string(pos))
      end
   end,
   on_punch = furniture.punch
})
